package sseGameApps.controller.mdkbr.main;

import java.util.HashMap;
import java.util.Map;

import org.slim3.controller.Navigation;

import sseGameApps.controller.JsonController;
import sseGameApps.model.mdkbr.MdKbrUser;
import sseGameApps.model.mdkbr.MdUseKanji;
import sseGameApps.service.mdkbr.MdKanjiService;
import sseGameApps.service.mdkbr.MdKbrUserService;

public class MdSummonStartController extends JsonController {

    private MdKanjiService serviceMdKanji = new MdKanjiService();
    private MdKbrUserService serviceMdKbrUser = new MdKbrUserService();

    @Override
    public Navigation run() throws Exception {

        MdUseKanji mdUsekanji = serviceMdKanji.getMdUseKanji(asString("userId"));
        MdKbrUser mdKbrUser =
                serviceMdKbrUser.getMdKbrUser(asString("userId"));

        Map<String, String> data = new HashMap<String, String>();

        if (mdKbrUser == null) {
            data.put("userExp", "0");
            data.put("userLevel", "1");
        } else {
            data.put("userExp", mdKbrUser.getUserExp().toString());
            data.put("userLevel", mdKbrUser.getUserLevel().toString());
        }

        if (mdUsekanji == null){
            data.put("holderKanji01", "");
            data.put("holderKanji02", "");
            data.put("holderKanji03", "");
            data.put("holderKanji04", "");
            data.put("holderKanji05", "");
            data.put("holderKanji06", "");
            data.put("holderKanji07", "");
            data.put("holderKanji08", "");
            data.put("usingKanji01", "");
            data.put("usingKanji02", "");
            data.put("usingKanji03", "");
        } else {
            data.put("holderKanji01", mdUsekanji.getHolderKanji01());
            data.put("holderKanji02", mdUsekanji.getHolderKanji02());
            data.put("holderKanji03", mdUsekanji.getHolderKanji03());
            data.put("holderKanji04", mdUsekanji.getHolderKanji04());
            data.put("holderKanji05", mdUsekanji.getHolderKanji05());
            data.put("holderKanji06", mdUsekanji.getHolderKanji06());
            data.put("holderKanji07", mdUsekanji.getHolderKanji07());
            data.put("holderKanji08", mdUsekanji.getHolderKanji08());
            data.put("usingKanji01", mdUsekanji.getUsingKanji01());
            data.put("usingKanji02", mdUsekanji.getUsingKanji02());
            data.put("usingKanji03", mdUsekanji.getUsingKanji03());

            Map<String, String> playerKanjiData = new HashMap<String, String>();

            playerKanjiData = serviceMdKanji.getPlayerKanjiData(mdUsekanji);

            data.put("kanji01Bp", playerKanjiData.get("kanji01Bp"));
            data.put("kanji02Bp", playerKanjiData.get("kanji02Bp"));
            data.put("kanji03Bp", playerKanjiData.get("kanji03Bp"));
            data.put("kanji04Bp", playerKanjiData.get("kanji04Bp"));
            data.put("kanji05Bp", playerKanjiData.get("kanji05Bp"));
            data.put("kanji06Bp", playerKanjiData.get("kanji06Bp"));
            data.put("kanji07Bp", playerKanjiData.get("kanji07Bp"));
            data.put("kanji08Bp", playerKanjiData.get("kanji08Bp"));

            data.put("kanji01Ap", playerKanjiData.get("kanji01Ap"));
            data.put("kanji02Ap", playerKanjiData.get("kanji02Ap"));
            data.put("kanji03Ap", playerKanjiData.get("kanji03Ap"));
            data.put("kanji04Ap", playerKanjiData.get("kanji04Ap"));
            data.put("kanji05Ap", playerKanjiData.get("kanji05Ap"));
            data.put("kanji06Ap", playerKanjiData.get("kanji06Ap"));
            data.put("kanji07Ap", playerKanjiData.get("kanji07Ap"));
            data.put("kanji08Ap", playerKanjiData.get("kanji08Ap"));

            data.put("kanji01Type", playerKanjiData.get("kanji01Type"));
            data.put("kanji02Type", playerKanjiData.get("kanji02Type"));
            data.put("kanji03Type", playerKanjiData.get("kanji03Type"));
            data.put("kanji04Type", playerKanjiData.get("kanji04Type"));
            data.put("kanji05Type", playerKanjiData.get("kanji05Type"));
            data.put("kanji06Type", playerKanjiData.get("kanji06Type"));
            data.put("kanji07Type", playerKanjiData.get("kanji07Type"));
            data.put("kanji08Type", playerKanjiData.get("kanji08Type"));

            data.put("kanji01TypeTxt", playerKanjiData.get("kanji01TypeTxt"));
            data.put("kanji02TypeTxt", playerKanjiData.get("kanji02TypeTxt"));
            data.put("kanji03TypeTxt", playerKanjiData.get("kanji03TypeTxt"));
            data.put("kanji04TypeTxt", playerKanjiData.get("kanji04TypeTxt"));
            data.put("kanji05TypeTxt", playerKanjiData.get("kanji05TypeTxt"));
            data.put("kanji06TypeTxt", playerKanjiData.get("kanji06TypeTxt"));
            data.put("kanji07TypeTxt", playerKanjiData.get("kanji07TypeTxt"));
            data.put("kanji08TypeTxt", playerKanjiData.get("kanji08TypeTxt"));

        }
        data.put("userId", asString("userId"));
        data.put("firstLogin", asString("firstLogin"));
        data.put("idCanvas", asString("idCanvas"));

        this.toJson(data);

        return null;
    }
}
